<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Flashgame
 * @version    $Id: index.tpl 6159 2010 YouNet $
 * @author     To Anh
 */
?>

<script type="text/javascript">
<!--
  en4.core.runonce.add(function(){
    $$('#filter_form input[type=text]').each(function(f) {
        if (f.value == '' && f.id.match(/\min$/)) {
            new OverText(f, {'textOverride':'min','element':'span'});
            //f.set('class', 'integer_field_unselected');
        }
        if (f.value == '' && f.id.match(/\max$/)) {
            new OverText(f, {'textOverride':'max','element':'span'});
            //f.set('class', 'integer_field_unselected');
        }
    });
  });
-->
</script>
<?php
    $this->headLink()
        ->appendStylesheet($this->baseUrl() . '/application/modules/Flashgame/externals/styles/main.css');
?>


<div class='layout_right'>
  <?php echo $this->form->render($this) ?>
  <?php if( $this->can_create): ?>
    <div class="quicklinks">
      <ul>
        <li>
          <a href='<?php echo $this->url(array(), 'flashgame_create', true) ?>' class='buttonlink icon_flashgame_new'><?php echo $this->translate('Post New Game');?></a>
        </li>
      </ul>
    </div>
  <?php endif; ?>
</div>

<div class='layout_middle'>
  <?php if( $this->tag ): ?>
    <h3>
      <?php echo $this->translate('Showing games using the tag');?> #<?php echo $this->tag_text;?> <a href="<?php echo $this->url(array('module' => 'flashgame', 'controller' => 'index', 'action' => 'index'), 'default', true) ?>">(x)</a>
    </h3>
  <?php endif; ?>
  
  <?php if( $this->start_date ): ?>
    <?php foreach ($this->archive_list as $archive): ?>
      <h3>
        <?php echo $this->translate('Showing games created on');?> <?php if ($this->start_date==$archive['date_start']) echo $archive['label']?> <a href="<?php echo $this->url(array('module' => 'flashgame', 'controller' => 'index', 'action' => 'index'), 'default', true) ?>">(x)</a>
      </h3>
    <?php endforeach; ?>
  <?php endif; ?>

  <?php if( $this->paginator->getTotalItemCount() > 0 ): ?>
    <ul class="flashgames_browse">
      <?php foreach( $this->paginator as $item ): ?>
        <li>
          <div class='flashgames_browse_info'>
            <div class='flashgames_browse_info_title'>
              <div class='flashgames_browse_photo'>
			  <?php
				if ($item->photo_id) echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'thumb.normal'));
				else echo $this->htmlLink($item->getHref(),'<img alt="" src="application/modules/Flashgame/externals/images/nophoto.png">');
			  ?>
			  </div>
			  <h3>
			  <?php 
                    if (strlen($item->getTitle())>20) 
                        $gtitle = substr(strip_tags($item->getTitle()),0,20)."...";
                    else
                        $gtitle = substr(strip_tags($item->getTitle()),0,20);
              ?>
              <?php echo $this->htmlLink($item->getHref(), $gtitle) ?>
              
              <?php if( $item->paid ): ?>
                <img src='application/modules/Flashgame/externals/images/coin.png'/>
              <?php endif;?>
              </h3>
            </div>
            <div class='flashgames_browse_info_date'>
              <?php echo $this->timestamp(strtotime($item->creation_date)) ?>
              - <?php echo $this->translate('posted by');?> <?php echo $this->htmlLink($item->getOwner()->getHref(), $item->getOwner()->getTitle()) ?>
              
              <div>
                <?php for($i = 1; $i <= 5; $i++): ?>
                  <img border="0" src="application/modules/Flashgame/externals/images/<?php if ($i <= $item->rates): ?>star_full.png<?php elseif( $i > $item->rates &&  ($i-1) <  $item->rates): ?>star_part.png<?php else: ?>star_none.png<?php endif; ?>" width="10px" />
                <?php endfor; ?>
              </div>
            </div>
            <div class='flashgames_browse_info_blurb'>
              <?php $fieldStructure = Engine_Api::_()->fields()->getFieldsStructurePartial($item)?>
              <?php echo $this->fieldValueLoop($item, $fieldStructure) ?>
              <?php
                // Not mbstring compat
                echo substr(strip_tags($item->body), 0, 70); if (strlen($item->body)>70) echo "...";
              ?>
            </div>
          </div>
        </li>
      <?php endforeach; ?>
    </ul>

  <?php elseif( $this->category || $this->show == 2 || $this->search ):?>
    <div class="tip">
      <span>
        <?php echo $this->translate('Nobody has posted a game with that criteria.');?>
        <?php if ($this->can_create): ?>
          <?php echo $this->translate('Be the first to %1$spost%2$s one!', '<a href="'.$this->url(array(), 'flashgame_create').'">', '</a>'); ?>
        <?php endif; ?>
      </span>
    </div>
  <?php else:?>
    <div class="tip">
      <span>
        <?php echo $this->translate('Nobody has posted a game yet.');?>
        <?php if ($this->can_create): ?>
          <?php echo $this->translate('Be the first to %1$spost%2$s one!', '<a href="'.$this->url(array(), 'flashgame_create').'">', '</a>'); ?>
        <?php endif; ?>
      </span>
    </div>
  <?php endif; ?>
  <div>
    <?php echo $this->paginationControl($this->paginator, null, array("pagination/pagination.tpl","flashgame")); ?>
  </div>
</div>